package javachongkao.编程基础.数字各位数之和;

import java.util.Scanner;
//7-65 Sum of the digits
//Given a none-negative number, print out the sum of its digits.
//
//Input Format:
//A none-negative integer number.
//
//Output Format:
//The sum of its all digits.
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int number = scanner.nextInt(); // 读取非负整数
        int sum = sumDigits(number); // 计算各位数字之和
        System.out.println(sum); // 输出结果
    }

    // 方法：计算一个整数各个位上的数字之和
    public static int sumDigits(int num) {
        int sum = 0;
        while (num > 0) {
            sum += num % 10; // 取出最后一位数字并加到sum上
            num /= 10; // 去掉最后一位数字
        }
        return sum;
    }
}